package com.hainiu.cat.web.controller;

import com.hainiu.cat.web.config.TopicRabbitConfig;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * create by biji.zhao on 2021/6/4
 */
@RestController
public class SendTopicMessageController {

    private static final String RETURN_MESSAGE = "ok";

    @Autowired
    RabbitTemplate rabbitTemplate;

    /**
     * 预期可以发送成功的消息
     * @param message 消息
     * @return 返回提示信息
     */
    @GetMapping("/sendTopicMessage")
    public String sendFanoutMessage(String message) {
        rabbitTemplate.convertAndSend(TopicRabbitConfig.TOPIC_EXCHANGE, TopicRabbitConfig.TOPIC_FIRST_ROUTING_KEY, message);
        return RETURN_MESSAGE;
    }

    /**
     * 预期可以发送成功的消息
     * @param message 消息
     * @return 返回提示信息
     */
    @GetMapping("/sendTopicMessageSpecial")
    public String sendTopicMessageSpecial(String message) {
        rabbitTemplate.convertAndSend(TopicRabbitConfig.TOPIC_EXCHANGE, TopicRabbitConfig.TOPIC_SECOND_ROUTING_KEY, message);
        return RETURN_MESSAGE;
    }
}
